﻿using System;
using System.IO;
using System.Xml;
using YArchitech.LIB;

namespace ModelValidation.Utils
{
	public class DistanceXMLLoader
	{
		private bool IsFileExist()
		{
			return File.Exists(Product.InstallLocation + this.m_strFileName);
		}

		public bool TryGetValue(int index, out string strFormName, out string strPath)
		{
			strFormName = null;
			strPath = null;
			if (!this.IsFileExist())
			{
				return false;
			}
			string filename = Product.InstallLocation + this.m_strFileName;
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.Load(filename);
			XmlNode documentElement = xmlDocument.DocumentElement;
			int num = 0;
			foreach (object obj in documentElement.ChildNodes)
			{
				XmlNode xmlNode = (XmlNode)obj;
				if (xmlNode is XmlElement && (xmlNode as XmlElement).Name.Equals(this.m_strkeyNodeName) && int.TryParse((xmlNode as XmlElement).GetAttribute(this.m_strIndexParameterName), out num) && num == index)
				{
					foreach (object obj2 in (xmlNode as XmlElement).ChildNodes)
					{
						XmlNode xmlNode2 = (XmlNode)obj2;
						if (xmlNode2 is XmlElement && (xmlNode2 as XmlElement).Name.Equals(this.m_strFormNameNodeName))
						{
							strFormName = (xmlNode2 as XmlElement).InnerText;
						}
						if (xmlNode2 is XmlElement && (xmlNode2 as XmlElement).Name.Equals(this.m_strXmlPathNodeName))
						{
							strPath = (xmlNode2 as XmlElement).InnerText;
						}
					}
					return true;
				}
			}
			return false;
		}

		private string m_strFileName = "\\Data\\GetDistance.xml";

		private string m_strkeyNodeName = "DistanceCmdType";

		private string m_strIndexParameterName = "index";

		private string m_strFormNameNodeName = "ResultFormName";

		private string m_strXmlPathNodeName = "ReferenceXmlPath";
	}
}
